function NPC(/*tile*/ tile, /*vec2*/ position){
	this.inMap = true;
	this.behaviour = 0;       //0: Stand, 1: RandomWalk, 2: Pattern
	this.walkPattern = null;  //If the behaviour is 2, then a walkPattern is needed
	this.moveStep = 0;        //If the behaviour is 2, then this is the current step
	
	Character.call(this, tile, position);
}

NPC.prototype = Object.create(Character.prototype);
NPC.prototype.constructor = NPC;

NPC.prototype.createPath = function(path){
	this.walkPattern = [];
	for (var i=0,len=path.length;i<len;i++){
		var d = path[i];
		if (d == 'R') this.walkPattern.push(vec2( 1, 0)); else
		if (d == 'L') this.walkPattern.push(vec2(-1, 0)); else
		if (d == 'U') this.walkPattern.push(vec2( 0,-1)); else
		if (d == 'D') this.walkPattern.push(vec2( 0, 1));
	}
	
	console.log(this.walkPattern);
};

NPC.prototype.randomMovement = function(){
	var xx = Math.iRandom(-1,1);
	var yy = (xx == 0)? Math.iRandom(-1,1) : 0;
	
	if (xx != 0 || yy != 0){
		this.moveTo(vec2(xx, yy));
	}
};

NPC.prototype.patternMovement = function(){
	var step = this.walkPattern[this.moveStep];
	if (this.moveTo(step)){
		this.moveStep++;
		if (this.moveStep == this.walkPattern.length)
			this.moveStep = 0;
	}
};

NPC.prototype.step = function(){
	var player = this.mapManager.player;
	if (!player.action) return;
	
	if (this.behaviour == 1){
		this.randomMovement();
	}else if (this.behaviour == 2){
		this.patternMovement();
	}
};

NPC.prototype.draw = function(){
	if (this.mapManager.getVisible(this.position.a, this.position.b) != 2)
		return;
	Character.prototype.draw.call(this);
};

NPC.prototype.loop = function(){
	this.step();
	this.draw();
};